extends BaseDlg

var utils = null

# Called when the node enters the scene tree for the first time.
func _ready():
	utils = sys.get_node("VEBase").utils

# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
#	pass
var item
func init(item):
	self.item = item
	var box1 = $TabContainer.get_node("伤害/VBoxContainer")
	var box2 = $TabContainer.get_node("承伤/VBoxContainer")

	var sks = item.dmgData.keys()
	sks.sort_custom(self, "sortSk")

	var totalDmg = 0
	for i in item.dmgData.values():
		totalDmg = totalDmg + i

	for sk in sks:
		var dmg = item.dmgData[sk]
		newCol(sk,int(dmg),int(dmg/totalDmg*100),box1)
		continue

	var chas = item.hurtData.keys()
	chas.sort_custom(self, "sortAtkCha")

	var totalHurt = 0
	for i in item.hurtData.values():
		totalHurt = totalHurt + i

	for c in chas:
		var dmg = item.hurtData[c]
		newCol(c,int(dmg),int(dmg/totalHurt*100),box2,'#ffd100')
		continue

func newCol(name,val,per,fa,color = '#12ab11'):
	var hbox = HBoxContainer.new()
	utils.createRichTextLabel("[center][color=#BDB76B]%s[/color][/center]"%name,hbox,Vector2(100,35))
	var c = Control.new()
	var perBg = ColorRect.new()
	perBg.color = Color(color)
	perBg.rect_size = Vector2(per*305/100,25)
	c.add_child(perBg)
	utils.createRichTextLabel(" %d"%val,c,Vector2(297,35))
	utils.createRichTextLabel("[right]%d%%[/right]"%per,c,Vector2(297,35))
	hbox.add_child(c)
	fa.add_child(hbox)

func sortSk(a, b):
	return item.dmgData[a] > item.dmgData[b]

func sortAtkCha(a, b):
	return item.hurtData[a] > item.hurtData[b]
